﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using IdeaNMR.Web.Core;
using System.Text.RegularExpressions;

namespace IdeaNMR.Web
{
    public abstract class ListHardObjects_BaseTable<TObj> : ListBaseObjects_BaseTable<TObj>
        where TObj : HardObject, IHardObjectRelations
    {
        protected override Item[] FilterRawData()
        {
            IEnumerable<Item> result = base.FilterRawData();

            if (this.SearchTerms.Length > 0)
            {
                var res1 = from r in this.RawData
                           where
                              r.Obj.ContactPerson.ToLowerInvariant().Split(' ').Any(d => Regex.IsMatch(d, this.SearchRegEx) ) ||
                              r.Obj.Location.ToLowerInvariant().Split(' ').Any(l => Regex.IsMatch(l, this.SearchRegEx))
                           select r;
                result = result.Union(res1);
            }

            return result.ToArray();
        }
    }
}